Time and logarithmic scales
An axis in LiveCharts always works with double values. To plot dates, durations or a logarithmic scale, the data is
turned into a number when it is mapped, and the axis turns that number back into a label. LiveCharts includes an axis
for each case: DateTimeAxis and TimeSpanAxis read the values as ticks, and LogarithmicAxis reads them as the
exponent of a base. This article covers only what these axes change; for the rest of the axis properties see the
axes article.
This article highlights the most used features. Every property is listed in the API explorer:
DateTimeAxis,
TimeSpanAxis,
LogarithmicAxis,
DateTimePoint and
TimeSpanPoint.
In XAML, declare the axes as XamlDateTimeAxis, XamlTimeSpanAxis and XamlLogarithmicAxis.
Date time axis
A DateTimePoint has a DateTime and a Value. Its X coordinate is DateTime.Ticks and its Y coordinate is the
value; a null value leaves a gap. A DateTimeAxis on the X axis turns the ticks back into dates for the labels and
the tooltips. In XAML, the XamlDateTimeAxis takes the unit in Interval, one day by default, and the
label format in DateFormatter, a Func<DateTime, string>. Without a DateFormatter the labels use the short date
format ("d").

<UserControl x:Class="WinUISample.Axes.DateTimeScaled.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Axes.DateTimeScaled"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlColumnSeries Values="{Binding Values}"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<!--
The Interval property is used to set the interval between each label,
in this case, the interval is set to 1 day.
In the DateFormatter property, we define the format of the labels.
-->
<lvc:CartesianChart.XAxes>
<lvc:AxesCollection>
<lvc:XamlDateTimeAxis
Interval="1.00:00:00"
DateFormatter="{Binding Formatter}"/>
</lvc:AxesCollection>
</lvc:CartesianChart.XAxes>
</lvc:CartesianChart>
</UserControl>
using System;
using LiveChartsCore.Defaults;
namespace ViewModelsSamples.Axes.DateTimeScaled;
public class ViewModel
{
public DateTimePoint[] Values { get; set; } = [
new() { DateTime = new(2021, 1, 1), Value = 3 },
new() { DateTime = new(2021, 1, 2), Value = 6 },
new() { DateTime = new(2021, 1, 3), Value = 5 },
new() { DateTime = new(2021, 1, 4), Value = 3 },
new() { DateTime = new(2021, 1, 5), Value = 5 },
new() { DateTime = new(2021, 1, 6), Value = 8 },
new() { DateTime = new(2021, 1, 7), Value = 6 }
];
public Func<DateTime, string> Formatter { get; set; } =
date => date.ToString("MMMM dd");
}
In code, the constructor takes the unit and the function that formats each label:
Series = new ISeries[]
{
new ColumnSeries<DateTimePoint>
{
Values = new DateTimePoint[]
{
new(new DateTime(2021, 1, 1), 3),
new(new DateTime(2021, 1, 2), 6),
new(new DateTime(2021, 1, 3), 5)
}
}
};
XAxes = new[]
{
new DateTimeAxis(TimeSpan.FromDays(1), date => date.ToString("MMMM dd")) // mark
};
The unit
The unit of a DateTimeAxis is the distance between two consecutive points, one day in the sample above. The axis
uses it twice:
UnitWidthis set to the unit, in ticks. Series drawn with bars, such as columns, candlesticks and boxes, take the width of each bar from it, so with the defaultUnitWidthof1a bar would be one tick wide.MinStepis set to the unit, so the axis never draws two labels closer than one unit. The step is calculated in units too: 1, 2, 5, 10, 20 days and so on in the sample. SetForceStepToMintotrueto draw a label on every unit.
Pick the unit that matches your data: TimeSpan.FromHours(1) for hourly points, or an average such as
TimeSpan.FromDays(30.4375) for months and TimeSpan.FromDays(365.25) for years, since months and years do not have
a fixed length.
Because the values are ticks, the limits of the axis are ticks too, for example
MinLimit = new DateTime(2021, 1, 1).Ticks. The
financial series
article shows the same axis with candlesticks.
Dates in your own types
DateTimePoint is optional. Any type works when its mapper returns the ticks as the X coordinate. A DateTimeAxis is
an Axis with UnitWidth, MinStep and Labeler already set, so a plain Axis with the same properties works the
same way; the AsDate() extension in the LiveChartsCore namespace converts the double back into a DateTime:
Series = new ISeries[]
{
new LineSeries<Sale>
{
Values = sales,
Mapping = (sale, index) => new(sale.Date.Ticks, sale.Total) // mark
}
};
XAxes = new[]
{
new Axis
{
UnitWidth = TimeSpan.FromDays(1).Ticks, // mark
MinStep = TimeSpan.FromDays(1).Ticks, // mark
Labeler = value => value.AsDate().ToString("MMM dd") // mark
}
};
See mappers for more about mapping your own types.
Time span axis
TimeSpanPoint and TimeSpanAxis do the same for durations: the X coordinate is TimeSpan.Ticks, and the
constructor of the axis takes the unit and a Func<TimeSpan, string> that formats each label. This sample uses a unit
of one millisecond: new TimeSpanAxis(TimeSpan.FromMilliseconds(1), value => $"{value:fff}ms"). In XAML,
the XamlTimeSpanAxis takes the unit in Interval and the format in TimeFormatter.

<UserControl x:Class="WinUISample.Axes.TimeSpanScaled.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Axes.TimeSpanScaled"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlColumnSeries Values="{Binding Values}"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<!--
The Interval property is used to set the interval between each label,
in this case, the interval is set to 1 millisecond.
In the DateFormatter property, we define the format of the labels.
-->
<lvc:CartesianChart.XAxes>
<lvc:AxesCollection>
<lvc:XamlTimeSpanAxis
Interval="0:0:0.001"
TimeFormatter="{Binding Formatter}"/>
</lvc:AxesCollection>
</lvc:CartesianChart.XAxes>
</lvc:CartesianChart>
</UserControl>
using System;
using LiveChartsCore.Defaults;
namespace ViewModelsSamples.Axes.TimeSpanScaled;
public class ViewModel
{
public TimeSpanPoint[] Values { get; set; } = [
new () { TimeSpan = TimeSpan.FromMilliseconds(1), Value = 10 },
new () { TimeSpan = TimeSpan.FromMilliseconds(2), Value = 6 },
new () { TimeSpan = TimeSpan.FromMilliseconds(3), Value = 3 },
new () { TimeSpan = TimeSpan.FromMilliseconds(4), Value = 12 },
new () { TimeSpan = TimeSpan.FromMilliseconds(5), Value = 8 }
];
public Func<TimeSpan, string> Formatter { get; set; } =
value => $"{value:fff}ms";
}
The fff format shows only the milliseconds part of the duration; for longer spans use a format that includes the
seconds or minutes, or a property such as TotalMilliseconds.
Logarithmic axis
A LogarithmicAxis does not transform the data. The data must be mapped to its logarithm, and the axis turns each
exponent back into a value for the labels and the tooltips: with base 10, the value 3 on the axis is labeled
1,000.00. The base of the axis and the base of the mapper must be the same.
This sample registers a mapper for the LogarithmicPoint class that takes the base 10 logarithm of Y, and uses a
LogarithmicAxis with base 10 on the Y axis (XamlLogarithmicAxis with LogBase in XAML):

<UserControl
x:Class="WinUISample.Axes.Logarithmic.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Axes.Logarithmic"
xmlns:local="using:WinUISample.Axes.Logarithmic"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<local:LogarithmicSeries Values="{Binding Values}"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.YAxes>
<lvc:AxesCollection>
<lvc:XamlLogarithmicAxis
LogBase="{Binding LogBase}"
SeparatorsPaint="{lvc:SolidColorPaint Color='#64b4b4b4'}"
SubseparatorsPaint="{lvc:SolidColorPaint
Color='#64b4b4b4',
StrokeWidth=0.5}"
SubseparatorsCount="9"/>
</lvc:AxesCollection>
</lvc:CartesianChart.YAxes>
</lvc:CartesianChart>
</UserControl>
using System;
using LiveChartsCore;
namespace ViewModelsSamples.Axes.Logarithmic;
public class ViewModel
{
public ViewModel()
{
LiveCharts.Configure(config =>
config.HasMap<LogarithmicPoint>(
(logPoint, index) => new(logPoint.X, Math.Log(logPoint.Y, LogBase))));
}
// base 10 log, change the base if you require it.
// or use any custom scale the logic is the same.
public double LogBase { get; set; } = 10;
public LogarithmicPoint[] Values { get; set; } = [
new(1, 1),
new(2, 10),
new(3, 100),
new(4, 1000),
new(5, 10000),
new(6, 100000),
new(7, 1000000),
new(8, 10000000)
];
}
namespace ViewModelsSamples.Axes.Logarithmic;
public class LogarithmicPoint(double x, double y)
{
public double X { get; set; } = x;
public double Y { get; set; } = y;
}
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.WinUI;
using ViewModelsSamples.Axes.Logarithmic;
namespace WinUISample.Axes.Logarithmic;
// WinUI xaml parser does not support generic types
// we instead create a non-generic class that inherits from the generic one.
public class LogarithmicSeries : XamlLineSeries<LogarithmicPoint> { }
LiveCharts.Configure registers the mapper for every series of that type in the application. To use it on one series
only, set the Mapping property of the series instead:
Series = new ISeries[]
{
new LineSeries<LogarithmicPoint>
{
Values = values,
Mapping = (point, index) => new(point.X, Math.Log(point.Y, 10)) // mark
}
};
YAxes = new[]
{
new LogarithmicAxis(10) // mark
};
Math.Log returns double.NaN for negative values, which LiveCharts draws as a gap, and double.NegativeInfinity
for 0, which it does not. Map zeros to Coordinate.Empty if your data can contain them, see
NaN and Infinity.
Log labels and subseparators
The axis sets MinStep to 1, so the separators fall on whole exponents, the powers of the base. Its Labeler
returns Math.Pow(base, value) with the "N2" format. To change the format, set your own Labeler and convert the
exponent back the same way:
new LogarithmicAxis(10)
{
Labeler = value => Math.Pow(10, value).ToString("N0") // mark
}
Subseparators are spaced on a logarithmic scale too, closer together as they approach the next power of the base.
Set SubseparatorsCount to the base minus one, 9 for base 10 as in the sample, so they fall on 2, 3, 4... 9 times
each power. Subseparators are only drawn when SubseparatorsPaint is set.